<template>
	<view class="wdthdrawal">
		<view class="pagetitle">
			<uni-breadcrumb separator="/">
				<uni-breadcrumb-item v-for="(route,index) in routes" :key="index" :to="route.to">
					{{route.name}}
				</uni-breadcrumb-item>
			</uni-breadcrumb>
			<view class="right">
				<view class="select">
					<uni-data-select
					   v-model="screenVal"
					   :localdata="screenrange"
						@change="changeScreen"
					></uni-data-select>
				</view>
				
				<view class="" style="display: flex;width:400px; margin:0 10px">
					<uni-easyinput errorMessage v-model="searchVal" focus placeholder="搜索内容" ></uni-easyinput>
					<button size="mini" plain style="margin:5rpx 10rpx;border:1px  solid #ccc" >搜索</button>
				</view>
				
			</view>
		</view>
		<uni-table ref="table" :loading="loading" :emptyText="data.length || '暂无提现申请'" border stripe type="selection" @selection-change="selectionChange">
			<uni-tr>
				<uni-th  align="center">商铺名称</uni-th>
				<uni-th  align="center">开户人</uni-th>
				<uni-th  align="center">开户银行</uni-th>
				<uni-th  align="center">银行卡证号</uni-th>
				<uni-th align="center">申请状态</uni-th>
				<uni-th align="center">提现金额</uni-th>
				<uni-th align="center">汇款时间</uni-th>
				<uni-th align="center">服务费</uni-th>
				<uni-th align="center">申请时间</uni-th>
				<uni-th  align="center" width="330" >设置</uni-th>
			</uni-tr>
			
			<uni-tr v-for="(item, index) in data" :key="index">
				<!-- 商铺名称 -->
				<uni-td align="center">
					<text class="titleApp">
						{{item.shop.title}}
					</text>
				</uni-td>
				<!-- 开户人 -->
				<uni-td align="center">
					{{ item.bank.properties.name }}
				</uni-td>
				<!-- 开户银行 -->
				<uni-td align="center">
					{{ onBankIs(item.bank.properties.bank_title) }}
				</uni-td>
				<!-- 银行卡号 -->
				<uni-td align="center">
					<text class="fontColorApp">
						{{ initBankNum(item.bank.properties.bank_no)}}
					</text>
				</uni-td>
				<!-- 申请状态 -->
				<uni-td align="center">
					<view class="items" >
						{{item.is_settlement.is_true?'已汇款': item.failure_note?item.failure_note:'待汇款'}}
					</view>
				</uni-td>
				<!-- 提现金额 -->
				<uni-td align="center" >
					<text class="fontColorApp">
						￥{{(item.price*10/1000).toFixed(2)}}
					</text>
				</uni-td>
				<!-- 汇款时间 -->
				<uni-td align="center">
					<uni-dateformat v-if="item.is_settlement.is_true" :date="item.is_settlement.create_time"></uni-dateformat>
					<view v-else >
						-  -
					</view>
				</uni-td>
				<!-- 服务费 -->
				<uni-td align="center">
					<view class=" " >
						<text class="fontColorApp">
							￥{{item.bank.serve_money}}
						</text>
					</view>
				</uni-td>
				<!-- 申请时间 -->
				<uni-td align="center">
					<uni-dateformat :date="item.create_date" format="yyyy-MM-dd hh:mm" ></uni-dateformat>
				</uni-td>
				<!-- 设置 -->
				<uni-td align="center" class="btn">
					<button :type="item.failure_note?'warn':'primary'" :disabled="item.failure_note||item.is_settlement.is_true" size="mini" @click="goUrl(`./examine-wdthdrawal-detail?billID=${item._id}`)" >
						{{item.is_settlement.is_true?'已汇款': item.failure_note?'汇款已拒绝':'待汇款'}}
					</button>
					<button  size="mini" @click="goUrl(`/pages/order/orders/orders?_uid=${item.shop_id}`)" >
						相关订单
					</button>
					<button  size="mini" @click="goUrl(`/pages/shop/shop_bill/list?_uid=${item.shop_id}`)" >
						相关账单
					</button>
				</uni-td>
			</uni-tr>
		</uni-table>
		<view class="uni-pagination-box">
			<uni-pagination @change="enventFneye" :v-model="currentPage" :pageSize="limit" title="" :total="total"></uni-pagination>
		</view>
	</view>
</template>

<script>
	import Util from "@/js_sdk/validator/util.js"
	const global = uniCloud.importObject("global",{customUI:true})
	let Where ;
	export default {
		data() {
			return {
				loading:true,
				routes: [
					{to: "/pages/index/index",name: "首页",},
					{to: "",name: "接待中心",},
					{to: "",name: "提现审核",},
				],
				// 分页
				total:0, //  总条数
				skip:0,// 开始查询位置
				limit:20, // 单词查询条数
				currentPage:1, // 当前页
				data:[],
				//a 日期下拉框
				screenVal:0,
				screenrange: [
				   { value: 0, text: "待提现" },
				   { value: 1, text: "已提现" },
				   { value: 2, text: "已驳回" },
					{ value: 3, text: "全部" }
				],
				
			}
		},
		onLoad() {
			Where = `bank!=null && is_settlement.is_true == ${false} && failure_note == null`
			this.getExamineData()
		},
		methods: {
			getExamineData(){
				global.getDataList("shop_bill",
					Where ,"create_date desc" , 
					"bank,create_date,is_settlement,order,price,shop_id,shop,text,failure_note,type",this.skip,this.limit
				).then(res=>{
					// console.log(res.data)
					// let money = 0 ;
					//  res.data.map(item => {
					// 	return money += parseInt((item.price/100).toFixed(0))
					// })
					// console.log(money);
					this.data = res.data
					this.total = res.count
					this.loading=false
				})
			},
			initBankNum(num){
				return Util.formatBankCardNumber(num)
			},
			// 分页
			enventFneye(val){
				this.skip = (val.current-1)*20
				this.getExamineData()
			},
			// 筛选条件
			changeScreen(e){
				if(e == 0){
					Where = `bank!=null && is_settlement.is_true == ${false} && failure_note == null`
				}else if (e == 1){
					Where =  `bank!=null && is_settlement.is_true == ${true}`
				}else if(e == 2){
					Where = `bank!=null && is_settlement.is_true == ${false} && failure_note != null`
				}else if(e == 3){
					Where = `bank!=null `
				}
				this.skip = 0
				this.currentPage = 1
				this.getExamineData()
			},
			onBankIs(bank){
				if(typeof bank == 'string'){
					return bank
				}
				else if (typeof bank == 'object') {
					return bank[0].label
				}
			},
			goUrl(Url){
				uni.navigateTo({
					url:Url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn{
		button{
			margin:0 5px
		}
	}
	.pagetitle{
		padding:10rpx;
		display: flex; justify-content: space-between; align-items:center;
		.right{
			display:flex;
		}
		.select{
			width:200px;
		}
	}
	.item{
		padding:30rpx;
		margin:30rpx;
		border-bottom:1rpx solid #eee;
		display: flex; justify-content: space-between;
		.items{
			flex: 1;
			text-align: center;
		}
	}
	.title{
		font-size:15px;font-weight: bold;
	}
	.table{
		margin:50rpx 20rpx;
		border:1px solid #eee;
		border-bottom:none
	}
	.wdthdrawal{
		padding:20rpx;
	}
</style>
